package main.canvas;

import main.utils.RiverConstants;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;

public class DisplayFrame extends JFrame {

    public DisplayFrame(JPanel mainPanel, GraphicsDevice device) {
        super(device.getDefaultConfiguration());
        setTitle(RiverConstants.APPLICATION_TITLE);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        setUndecorated(true);
        getContentPane().add(mainPanel);

        KeyAdapter resolutionListener = new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    dispatchEvent(new WindowEvent(DisplayFrame.this, WindowEvent.WINDOW_CLOSING));
                }
            }
        };
        addKeyListener(resolutionListener);
    }

    public void go() {
        setResizable(false);
        validate();
    }

}